import datetime

from django.conf import settings
from django.core.mail import send_mail
from equipments.models import Equipment
from book.models import Book
from equipments.serializers import EquipmentModelSerializer
from book.serializers import BookSerializer


def send_notify_email(to):
    send_mail(subject='设备过期提醒', message="您订阅的设备即将过期，请注意及时完成工作！", from_email=settings.EMAIL_HOST_USER,
              recipient_list=['2858600511@qq.com'])


def auto_release_equipment(bid, eid, to):
    book = Book.objects.get(b_id=bid)
    equipment = Equipment.objects.get(e_id=eid)
    equipment.e_status = 0
    book.end_time = datetime.datetime.now()
    book.b_status = 1
    equipment.save()
    book.save()
    send_mail(subject='设备释放提醒', message="您订阅的设备已经释放，如需使用请重新预定", from_email=settings.EMAIL_HOST_USER,
              recipient_list=[to])
